/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sdc.component.type;

import java.util.ArrayList;
import java.util.List;
import sdc.strategyfactory.DefaultStrategy;

/**
 *
 * @author yokoe
 */
public class ComponentTypeFactory {

	/**
	 * create component types up to typeNum, with fixed worklod.
	 * @param typeNum
	 * @param workload
	 */
	public static List<Integer> createComponentTypes(double rateOfSLA, int typeNum, double workload)
	{
		return createComponentTypes(rateOfSLA, typeNum, workload, workload);
	}


	/**
	 * create component types up to typeNum.
	 * workload values of each components are set incrementally as below.
	 * 
	 * workload of typeid i = minWorkload + delta + 1
	 * delta = max - min / typeNum - 1
	 * 
	 * @param typeNum
	 * @param minWorkload
	 * @param maxWorkload
	 */
	public static List<Integer> createComponentTypes(double rateOfSLA, int typeNum, double minWorkload, double maxWorkload)
	{
		if(typeNum <= 0) throw new IllegalArgumentException("Patamater typeNum should be positive.");
		if(minWorkload <= 0.0 || maxWorkload <= 0.0) throw new IllegalArgumentException("Patamater minWorkload and maxWrokLoad should be positive.");
		if(minWorkload > maxWorkload) throw new IllegalArgumentException("Parametar maxWorkLoad should be greater than minWorkLoad");


		double delta  = typeNum == 1 ? 0 : (maxWorkload - minWorkload) / (typeNum - 1);

		ArrayList<Integer> IDList = new ArrayList<Integer>();


		int newID = ComponentTypePool.INSTANCE.getTypeNum();

		for(int i = 0; i < typeNum; i++)
		{

                        double workload = minWorkload + delta * i;

			ComponentType componentType = new ComponentType(newID + i, workload, DefaultStrategy.INSTANCE, workload * rateOfSLA);

			ComponentTypePool.INSTANCE.register(newID + i, componentType);

			IDList.add(newID);
		}

                ComponentProbMatrixFactory tmp = new ComponentProbMatrixFactory();
                tmp.createProbMatrix(typeNum);
                ComponentTypePool.INSTANCE.setMatrix(tmp.getMatrix());
		return IDList;
	}
}
